<?php
class MHtmlDataColumn extends MHtmlColumn {
    private $_modelClass;
    private $_attribute;
    
    public function __construct($modelClass, $attribute, $table, $id = NULL) {
        $this->_modelClass = $modelClass;
        $this->_attribute = $attribute;
        parent::__construct($table, $id);
    }
    
    public function renderHeader() {
        $class = $this->_modelClass;
        if (array_key_exists($this->_attribute, $class::$attributeLabel)){
            return MHtml::tag('th', $this->_htmlOptions, __t($class::$attributeLabel[$this->_attribute]));
        } else {
            return MHtml::tag('th', $this->_htmlOptions, $this->_attribute);
        }
    }
    
    public function renderBody($rowIndex) {
        $model = $this->_table->getRow($rowIndex);
        $attribute = $this->_attribute;
        if (isset($model)){
            return MHtml::tag('td', $this->_htmlOptions, $model->$attribute);
        } else {
            return MHtml::tag('td', $this->_htmlOptions, '&nbsp;');
        }
    }
    
    public function getModelClass() {
        return $this->_modelClass;
    }

    public function setModelClass($_modelClass) {
        $this->_modelClass = $_modelClass;
    }

    public function getAttribute() {
        return $this->_attribute;
    }

    public function setAttribute($_attribute) {
        $this->_attribute = $_attribute;
    }
    
}
?>
